package com.example.demo.common;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Resource
    JwtInterceptor jwtInterceptor;

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.addPathPrefix("/api", clazz -> clazz.isAnnotationPresent(RestController.class));
    }

    //自定义拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor).addPathPatterns("/api/**")
                .excludePathPatterns("/api/admin/login")
                .excludePathPatterns("/api/admin/register")
                .excludePathPatterns("/api/files/**")
                .excludePathPatterns("/api/gkhomework/download/**")
                .excludePathPatterns("/api/gkhomework/preview/**")
                .excludePathPatterns("/api/gkpaper/preview/**")
                .excludePathPatterns("/api/gkpaper/download/**")
                .excludePathPatterns("/api/jkhomework/download/**")
                .excludePathPatterns("/api/jkhomework/preview/**")
                .excludePathPatterns("/api/documents/**")
                .excludePathPatterns("/api/user/register")
                .excludePathPatterns("/api/audit/**")
                .excludePathPatterns("/api/type/**")
                .excludePathPatterns("/api/notice/**")
                .excludePathPatterns("/api/v2/**")
                .excludePathPatterns("/api/swagger-resources")
                .excludePathPatterns("/api/webjars/**")
                .excludePathPatterns("/api/doc.html");




    }
}
